<?php
/**
 * Created by PhpStorm.
 * User: tri
 * Date: 6/16/14
 * Time: 5:13 PM
 */
require_once('../../class_ajax_request/classAjax.php');
include_once('../../application/functions.php');
include_once('../../application/DataConfig.php');
include_once('answer.content.function.php');
$html_button = '';

$post_type_slider_flag = 0;
$array_meta_silder = array();
$count_slider_vote = 0;
$array_meta = array();
$disable = false;
foreach($post_meta_array as $pos_meta)
{
    $postAnswerId = 0;

    //get value
    $post_type = $pos_meta['post_type'];
    $post_question = json_decode( $pos_meta['meta_value']);





    $post_id = $pos_meta['post_id'];
    $meta_id = $pos_meta['id'];
    $user_create = $pos_meta['user'];
    $extra_value = $pos_meta['extra_value'];
    //binary and multi
    $checkArray = $obj->checkAnswered($meta_id,$_SESSION['authenticated'] );
//    echo '<pre>';
//    print_r($checkArray);
//    echo '</pre>';
//    print_r($checkArray);

    $check = $checkArray[0]['count_check'];
    $postAnswerId = $checkArray[0]['postanswerid'];
//    echo '<input type="text" data-post-type="'.$post_type.'"value="'.$post_answer_id.'" >';
    echo '<div class="answer-info" data-post-type ="'.$post_type.'" data-answer-id="'.$postAnswerId.'" ></div>';

    if($post_type == 1 || $post_type == 2){
        //button
        //&& $_SESSION['authenticated'] != $user_create
//        echo 'check '.$check;
        if($check == 0  ){
            $html_button = get_default_button($meta_id, $post_id, $post_type, $post_question, $user_create, $disable);
            echo $html_button;
        }
        else{

            //html answer
            $obj = new AjaxRequest();
            $array_info = get_default_answer($obj, $post_id);

            $chart = '';
            if($post_type == 1 )
                $chart = binarychart($array_info,$post_id);
            if($post_type == 2 || $post_type == 4 ){
                $html_answer = get_slider_answer($obj,$post_id, 'RATING');

               $chart = $obj->renderBarChart($post_id,$post_question,$array_info);
            }

            echo $chart;
        }

    }
    //slider

    if($post_type == 3){
        //button
        if($check == 0 ){
            $slider_html = get_slider_html($meta_id, $post_id, $post_type, $post_question, $user_create,  $disable,$extra_value);
                echo $slider_html;
        }else{
            //html

            $html_answer = get_slider_answer($obj,$post_id, 'Average',$extra_value,$post_question);

            echo $html_answer;
        }


    }
    //star
    if($post_type == 4){
        if($check == 0 ){
            $html_button = get_default_button($meta_id, $post_id, $post_type, $post_question, $user_create,  $disable,$obj);
            echo $html_button;
        }else{
            $obj = new AjaxRequest();
            $array_info = get_default_answer($obj, $post_id);

            $html_answer = get_star_answer($obj,$post_id, 'RATING');
            $chart = $obj->renderBarChart($post_id,$post_question,$array_info);
          //  echo $html_answer;
            echo $html_answer;
           echo $chart;
       }
    }

} ?>
<style>
<?php if($check != 0){
    ?>

    #post-li-<?php  echo $key['id'] ?> .actions_content{
    display: block;
    }

<?php
}else{ ?>
    #post-li-<?php  echo $key['id'] ?> .actions_content{
    display: none!important;
    }
<?php
}?>
</style>

